//package com.dfs.parent.order.config;
//
//
//import com.alibaba.csp.sentinel.slots.block.BlockException;
//import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
//import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
//import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
//import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
//import com.alibaba.fastjson.JSONObject;
//import com.dfs.parent.common.core.domain.Result;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * @ClassName GlobalExceptionHandler
// * @Author hong
// * @Date 2019/9/21 2:19 PM
// * @Version 1.0
// **/
//@Slf4j
//@RestControllerAdvice
//public class GlobalExceptionHandler {
//
//    @ExceptionHandler(BlockException.class)
//    public Result myExceptionHandler(HttpServletRequest req, BlockException e) {
//        Result restObject = null;
//
//        if (e instanceof FlowException) {
//            // 限流
//            restObject = Result.fail(5001,"接口限流");
//        } else if (e instanceof DegradeException) {
//            // 降级
//            restObject = Result.fail(5002,"服务降级");
//        } else if (e instanceof ParamFlowException) {
//            // 热点参数
//            restObject = Result.fail(5003,"热点参数限流");
//        } else if (e instanceof SystemBlockException) {
//            // 系统保护
//            restObject = Result.fail(5004,"触发系统保护规则");
//        } else if (e instanceof AuthorityException) {
//            // 授权规则
//            restObject = Result.fail(5005,"授权规则不通过");
//        }
//        log.info(req.getRequestURI(),e);
//        return restObject;
//    }
//
//    @ExceptionHandler(Exception.class)
//    public Result baseExceptionHandler(HttpServletRequest req, Exception ex) {
//        log.error(req.getRequestURI(),ex);
//        return Result.fail(ex.getMessage());
//    }
////    @ExceptionHandler(value = BlockException.class)
////    public JSONObject myExceptionHandler(HttpServletRequest req, BlockException blockException) {
//////        log.info(req.getRequestURI(),ex);
//////        return Result.fail("Too many request, please retry later");
////        return new JSONObject().fluentPut("code", 1024)
////                .fluentPut("msg", "请求被拦截，拦截类型为 " + blockException.getClass().getSimpleName());
////
//////        return Result.fail(blockException.getMessage());
////    }
//
//}
